package com.drore.logapp.base;

import android.content.Context;

import com.drore.logapp.utils.NetUtils;
import com.drore.logapp.utils.ToastUtil;

import rx.Subscription;
import rx.subscriptions.CompositeSubscription;

/**
 * Created by xiangl
 * on 2018/4/24 0024 下午 2:53
 * description :
*/
public class BasePresenter<V extends BaseViewI> implements BasePresenterI {
    public V mView;
    public Context context;
    private CompositeSubscription mCompositeSubscription;

    @Override
    public boolean checkNetWork(Context context) {
        if(!NetUtils.checkNetWork(context)) {
            ToastUtil.show(context, "网络不可用，请检查网络");
        }
        return NetUtils.checkNetWork(context);
    }


    public void attachView(V view,Context context) {
        this.mView = view;
        this.context=context;
    }


    /**
     * 事件订阅
     * */
    protected void addSubscription(Subscription s) {
        if (this.mCompositeSubscription == null) {
            this.mCompositeSubscription = new CompositeSubscription();
        }
        this.mCompositeSubscription.add(s);
    }

    @Override
    public void unsubcrible() {
        if (this.mCompositeSubscription != null) {
            this.mCompositeSubscription.unsubscribe();
        }
        mView=null;
        context=null;
    }
}
